template <class charT, class traits> basic_ostream<charT,traits>& operator<< ( basic_ostream<charT,traits>& os, const error_code& ec );
1
os << ec.category.name() << ':' << ec.value()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// error_code::operator<<
#include <iostream> // std::cout, std::ios
#include <system_error> // std::system_error
#include <fstream> // std::ifstream
int main()
{
std::ifstream is;
is.exceptions (std::ios::failbit);
try {
is.open ("unexistent.txt");
} catch (const std::system_error& e) {
std::cout << "Exception caught:\n";
std::cout << e.code() << " = " << e.what() << '\n';
}
}
Exception caught: iostream:1 = ios_base::failbit set